package com.livegoods.message;

import com.livegoods.commons.pojo.LivegoosMessage;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.stereotype.Component;


public class LivegoodsMessagePublisher {


    //发送消息对象
    private AmqpTemplate amqpTemplate;

    /**
     * 消息对应发送消息同步方法
     * @param exchange mq的交换器
     * @param routingKey  mq的路由键
     * @param livegoosMessage 向mq中发送消息的数据
     * @return
     */
    public Object syncSendAndReceiveMessage(String exchange, String routingKey, LivegoosMessage livegoosMessage){

        Object result = amqpTemplate.convertSendAndReceive(exchange, routingKey, livegoosMessage);
        System.out.println("result = " + result);
        return result;
    }
    /**
     * 消息对应发送消息异步方法
     * @param exchange mq的交换器
     * @param routingKey  mq的路由键
     * @param livegoosMessage 向mq中发送消息的数据
     * @return
     */
    public void aSyncSendAndReceiveMessage(String exchange, String routingKey, LivegoosMessage livegoosMessage){

        amqpTemplate.convertAndSend(exchange,routingKey,livegoosMessage);

    }


    public void setAmqpTemplate(AmqpTemplate amqpTemplate) {
        this.amqpTemplate = amqpTemplate;
    }
}
